package com.caterina.resources;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JPanel;

import com.caterina.components.CLabel;
import com.caterina.components.CPanel;

public class CModules {
	public static CPanel formatForPairs(String tag,Component comp){
		if (comp==null)return new CPanel();
		if (tag==null||tag.equals(""))tag="";
		else tag+=": ";
		CPanel panel=new CPanel(new BorderLayout());
		CPanel retPanel=new CPanel(new BorderLayout());
		CLabel tagLbl=new CLabel(tag);
		tagLbl.setFont(CFont.CLABEL_TAG);
		tagLbl.setMinimumSize(new Dimension(2,600));
		tagLbl.setPreferredSize(new Dimension(200,25));
		panel.add(tagLbl,BorderLayout.WEST);
		panel.add(comp,BorderLayout.CENTER);
		retPanel.add(panel,BorderLayout.WEST);
		retPanel.setBorder(BorderFactory.createEmptyBorder(1, 10, 0, 0));
		retPanel.setOpaque(false);
		return retPanel;
	}
	public static CPanel formatPanelForReadOnlyPairs(String tag,String content){
		return CModules.formatForPairs(tag, new CLabel(content));
	}
	public static String formatForReadOnlyPairs(String tag,String content){
		return "<html><table><tr><td><b>"+tag+":&nbsp;</b></td><td>"+ content+"</td></tr></table></html>";
	}
	public static CPanel formatForList(String header,String memo,Component marker,boolean isSelected){
		CPanel retPanel =new CPanel(new BorderLayout());
		CPanel infoPanel=new CPanel();
		infoPanel.setLayout(new BoxLayout(infoPanel,BoxLayout.X_AXIS));
		infoPanel.setAlignmentX(JPanel.LEFT_ALIGNMENT);
		CLabel retLabel=new CLabel("<html><table><tr><td><b>"+header+"</b></td></tr><tr><td>"+memo+"</td></tr></table></html>");
		retPanel.add(infoPanel,BorderLayout.CENTER);
		retPanel.add(marker,BorderLayout.EAST);
		infoPanel.add(retLabel);
		infoPanel.setOpaque(false);
		if (isSelected){
			infoPanel.setForeground(CColors.LIST_ENTRY_HIGHLIGHT_TITLE_FOREGROUND);
			retPanel.setBackground(CColors.LIST_ENTRY_HIGHLIGHT_BACKGROUND);
		}
		retPanel.setBorder(BorderFactory.createMatteBorder(1, 2, 1, 15, retPanel.getBackground()));
		return retPanel;
	}
	public static CPanel formatForList(String header,String memo,String markerImageUrl,boolean isSelected){
		CLabel labelImg=new CLabel("");
		labelImg.setIcon(new ImageIcon(markerImageUrl));
		return formatForList(header, memo,labelImg,isSelected);
	}
	public static CPanel formatForList(String header,String memo,boolean isSelected){
		return formatForList(header, memo,new CLabel(""),isSelected);
	}
}
